using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace KsWare.Breconium.Core {

	public interface ITraceable {
#if(TRACE)
		void Trace(string message);
		
		void Trace(string message,object value);
#endif
	}

	public class TraceableObject:ITraceable {
#if(TRACE)
		readonly List<TraceEntry> mTrace=new List<TraceEntry>(); 


		public void Trace(string message) { mTrace.Add(new TraceEntry{Timestamp = DateTime.Now,Message = message}); }


		public void Trace(string propertyName,object value){ mTrace.Add(new TraceEntry{Timestamp = DateTime.Now, Message = "Property changed 'State' = '"+value+"'"}); }

		public string VisualizeTrace {
			get {
				var s=new StringBuilder();
				foreach (var entry in mTrace) {
					s.AppendLine(entry.ToString());
				}
				if(s.Length>0) s.Remove(s.Length - 2, 2);
				return s.ToString();
			}
		}
#endif
	}

	public class TraceEntry {
		public DateTime Timestamp { get; set; }
		public string Message { get; set; }

		public override string ToString() {
			// return string.Format("{0:yyyy-MM-dd HH:mm:ss.fff} {1}",Timestamp,Message);
			return string.Format("{0:HH:mm:ss.fff} {1}",Timestamp,Message);
		}
	}
}